package com.sn.core.util;

import com.aliyun.oss.OSSClient;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Created by qingshengzheng on 18/5/25.
 * https://help.aliyun.com/document_detail/32013.html?spm=a2c4g.11186623.2.12.oUAgwr
 */
public class OssUtil {
    public static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
    public static String accessKeyId = "<yourAccessKeyId>";
    public static String accessKeySecret = "<yourAccessKeySecret>";

    public static void uploadInputStream(FileInputStream input, String bucket, String key) {
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        InputStream inputStream = null;
        ossClient.putObject(bucket, key, inputStream);
        ossClient.shutdown();
    }

    public static void uploadLocalFile(String localfilePath, String bucket, String key) {
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        InputStream inputStream = null;
        ossClient.putObject(bucket, key, inputStream);
        ossClient.shutdown();
    }

    public static void uploadByte(byte[] content, String bucket, String key) {
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        InputStream inputStream = null;
        ossClient.putObject(bucket, key, new ByteArrayInputStream(content));
    }


}
